﻿package mortal.game.view.copy.towerCopy.panel
{
    import com.greensock.*;
    import com.mui.controls.*;
    import com.mui.display.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import flash.geom.*;
    import mortal.common.global.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.copy.towerCopy.*;
    import mortal.game.view.copy.towerCopy.cellrender.*;
    import mortal.game.view.copy.towerCopy.other.*;
    import mortal.game.view.guide.*;
    import mortal.mvc.core.*;

    public class TowerPassInfoEnterPanel extends GSprite
    {
        protected var imgbg:ScaleBitmap;
        private var infoTxt:GTextFiled;
        protected var _suggTxt:GTextFiled;
        private var enterBtn:GLoadingButton;
        private var imgHLine:GBitmap;
        private var imgDLine:GBitmap;
        private var imgReward:GBitmap;
        private var itemList:GTileList;
        private var arrow:TowerArrow;
        protected var _numTitle:GBitmap;
        protected var _ganNum:BitmapNumberText;
        private var hasPassTxt:GTextFiled;
        private var _tween:TweenMax;
        private var _judgeRec:Rectangle;
        public var state:int = 0;
        public var level:int = 0;
        private var lockShow:Boolean = false;
        private var target:TowerPassInfoItem;

        public function TowerPassInfoEnterPanel()
        {
            this._judgeRec = new Rectangle(120, 170, 226, 225);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            this.imgbg = UIFactory.bg(0, 0, 213, 225, this, ImagesConst.taskTrackBg2);
            this.infoTxt = UIFactory.gTextField("", 0, 42, 212, 25, this, GlobalStyle.textFormatHuang2.setSize(14).center().setBold(true));
            this._suggTxt = UIFactory.gTextField("", 9, 64, 212, 25, this, GlobalStyle.textFormatHuang2.setSize(14).center().setBold(true));
            this.imgHLine = UIFactory.bitmap(ImagesConst.tower_win_hLine, 9, 90, this);
            this.imgDLine = UIFactory.bitmap(ImagesConst.tower_win_hLine, 9, 173, this);
            this.imgReward = UIFactory.bitmap(ImagesConst.tower_win_newFirstRdTitle, 59, 96, this);
            this.enterBtn = UIFactory.gLoadingButton(ImagesConst.tower_win_go2_upSkin, 29, 179, 157, 39, this);
            this.enterBtn.label = "";
            this.enterBtn.configEventListener(MouseEvent.MOUSE_DOWN, this.onMoveBtnMouseHandler);
            this.hasPassTxt = UIFactory.gTextField("<font size=\'18\' color=\'" + GlobalStyle.colorLv + "\'>" + Language.getString(70996) + "</font>", 65, 187, 103, 40, this, null, true);
            this.hasPassTxt.visible = false;
            this.itemList = UIFactory.tileList(30, 122, 270, 43, this);
            this.itemList.rowHeight = 42;
            this.itemList.columnWidth = 42;
            this.itemList.horizontalGap = 1;
            this.itemList.verticalGap = 1;
            this.itemList.rowCount = 6;
            this.itemList.setStyle("cellRenderer", TowerRewardsCellRenderer);
            addChild(this.itemList);
            this._numTitle = UIFactory.gBitmap(ImagesConst.tower_win_newGan, 75, 15, this);
            this._ganNum = UIFactory.bitmapNumberText(108, 15, "DailyNormalNum.png", 19, 21, -8, this, 13, 1);
            this._ganNum.text = "0";
            this.arrow = UICompomentPool.getUICompoment(TowerArrow) as TowerArrow;
            this.arrow.direction = GuideArrow.Right;
            addChild(this.arrow);
            StageMouseManager.instance.addRecEvent(this._judgeRec, this.mouseOverModuleHandler, this.mouseOutModuleHandler);
            return;
        }// end function

        public function set direction(param1:int) : void
        {
            this.arrow.direction = param1;
            return;
        }// end function

        public function refresh(param1:Boolean = false) : void
        {
            if (isDisposed)
            {
                return;
            }
            this.hasPassTxt.visible = false;
            if (this.level > 0)
            {
                this.itemList.dataProvider = Cache.instance.copy.tower.getPassRewardsByLevelDataProvider(this.level, 4, TowerModule.copyCode);
                this.itemList.drawNow();
            }
            if (this.state != 0)
            {
                switch(this.state)
                {
                    case TowerEnterConst.UnPass:
                    {
                        this.hasPassTxt.visible = false;
                        this.enterBtn.visible = true;
                        this.enterBtn.filterEnabled = false;
                        break;
                    }
                    case TowerEnterConst.HasPass:
                    {
                        this.hasPassTxt.visible = true;
                        this.enterBtn.visible = false;
                        this.enterBtn.filterEnabled = true;
                        break;
                    }
                    case TowerEnterConst.CurrentPass:
                    {
                        this.hasPassTxt.visible = false;
                        this.enterBtn.visible = true;
                        this.enterBtn.filterEnabled = true;
                        break;
                    }
                    default:
                    {
                        throw new Error("" + Language.getString(70996));
                        break;
                    }
                }
            }
            this.updateJudgeRect();
            if (this.arrow.direction == GuideArrow.Right)
            {
                this.arrow.x = 440;
                this.arrow.y = 105;
            }
            else if (this.arrow.direction == GuideArrow.Left)
            {
                this.arrow.x = -210;
                this.arrow.y = 75;
            }
            var _loc_2:* = int(this.level / 5) * 5 + this.level % 5;
            this._ganNum.text = "" + _loc_2;
            var _loc_3:* = TowerCopyConfig.instance.getTowerTipInfo(TowerModule.copyCode, this.level);
            this.infoTxt.text = Language.getString(70997) + _loc_3.bossName;
            this._suggTxt.text = Language.getString(70998) + _loc_3.power + "+";
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this.killTween();
            StageMouseManager.instance.removeRecEvent(this._judgeRec);
            this.imgbg = this.imgbg && this.imgbg.dispose(param1) ? (null) : (null);
            this.infoTxt = this.infoTxt && this.infoTxt.dispose(param1) ? (null) : (null);
            this._suggTxt = this._suggTxt && this._suggTxt.dispose(param1) ? (null) : (null);
            this.enterBtn = this.enterBtn && this.enterBtn.dispose(param1) ? (null) : (null);
            this.imgHLine = this.imgHLine && this.imgHLine.dispose(param1) ? (null) : (null);
            this.imgDLine = this.imgDLine && this.imgDLine.dispose(param1) ? (null) : (null);
            this.imgReward = this.imgReward && this.imgReward.dispose(param1) ? (null) : (null);
            this.itemList = this.itemList && this.itemList.dispose(param1) ? (null) : (null);
            this.arrow = this.arrow && this.arrow.dispose(param1) ? (null) : (null);
            this.hasPassTxt = this.hasPassTxt && this.hasPassTxt.dispose(param1) ? (null) : (null);
            this._numTitle = null;
            this._ganNum = null;
            return;
        }// end function

        private function onMoveBtnMouseHandler(event:MouseEvent) : void
        {
            if (this.level != Cache.instance.copy.tower.getCurrentLevel(TowerModule.copyCode))
            {
                return;
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.TowerEnterCopy, TowerModule.copyCode));
            return;
        }// end function

        public function showMe(param1:TowerPassInfoItem) : void
        {
            this.target = param1;
            this.lockShow = true;
            this.mouseOverModuleHandler();
            return;
        }// end function

        public function hideMe(param1:TowerPassInfoItem, param2:Boolean = false) : void
        {
            this.killTween();
            if (this.target === param1)
            {
                if (param2)
                {
                    this.alpha = 0;
                    this.visible = false;
                }
                else
                {
                    this.lockShow = false;
                    this.mouseOutModuleHandler();
                }
            }
            return;
        }// end function

        private function mouseOverModuleHandler() : void
        {
            this.visible = true;
            this.killTween();
            this.alpha = 0;
            this._tween = TweenMax.to(this, 0.3, {alpha:1});
            return;
        }// end function

        private function mouseOutModuleHandler() : void
        {
            if (!this.lockShow)
            {
                this.killTween();
                this._tween = TweenMax.to(this, 0.3, {alpha:0, onComplete:this.myFunction});
            }
            return;
        }// end function

        private function myFunction() : void
        {
            this.visible = false;
            return;
        }// end function

        private function killTween() : void
        {
            if (this._tween)
            {
                this._tween.kill();
            }
            return;
        }// end function

        private function updateJudgeRect() : void
        {
            var _loc_1:* = this.localToGlobal(new Point(0, 0));
            this._judgeRec.x = _loc_1.x;
            this._judgeRec.y = _loc_1.y;
            return;
        }// end function

    }
}
